package com.kangye.enterprise.frontdesk.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kangye.enterprise.frontdesk.entity.Region;
import com.kangye.enterprise.frontdesk.mapper.RegionMapper;
import com.kangye.enterprise.frontdesk.service.RegionService;
import com.kangye.enterprise.frontdesk.util.ViewJsonObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @program: enterprise
 * @description: 实现区域逻辑接口类
 * @author: 索腾龙
 * @create: 2021-05-27 18:54
 **/
@Service
@Transactional
public class RegionServiceImpl implements RegionService {
    @Autowired
    private RegionMapper regionMapper;
    //查询所有地区(索腾龙)
    @Override
    public ViewJsonObject<Region> selRegion(Integer page, Integer limit) {
        //把当前页和每页显示的条数传进来
        PageHelper.startPage(page, limit);
        //调用mapper方法
        List<Region> list = regionMapper.selRegion();
        //创建分页对象,把数据存在pageInfo里
        PageInfo<Region> pageInfo = new PageInfo<Region>(list);
        //返回json格式
        return new ViewJsonObject<>(pageInfo.getList(), pageInfo.getTotal());
    }
}